package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/8 17:30
 * @description
 */
public class Code515 {
    private List<Integer> result = new ArrayList<>();

    public List<Integer> largestValues(TreeNode root) {
        getNode(root, 0);
        return result;
    }

    private void getNode(TreeNode node, int level) {
        if (node != null) {
            if (result.size() <= level) {
                result.add(node.val);
            } else {
                result.set(level, Math.max(result.get(level), node.val));
            }
            level++;
            getNode(node.left, level);
            getNode(node.right, level);
        }
    }
}
